<!DOCTYPE html>
<html lang="zh-cn" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
	<meta name="renderer" content="webkit">
	<title></title>
	<link rel="stylesheet" th:href="@{/css/pintuer.css}">
	<link rel="stylesheet" th:href="@{/css/admin.css}">
	<link rel="stylesheet" th:href="@{/md/css/editormd.css}"/>
	<link rel="stylesheet" th:href="@{/layui/css/layui.css}"/>
	<style>
		.r{
			display:inline-block
		}
		.yuan{
			margin-left: 2px;
			padding-left: 10px;
			border-radius:25px;
			border: 0px;
		}
		.bg{
			background-color: #e7e7e7;
		}
		.layui-form-select dl {overflow: auto; max-height:185px; }
	</style>
</head>
<body>
<div class="bg panel admin-panel">
	<form name="mdEditorForm" class="layui-form layui-form-pane">
		<div class="panel-head">
			<strong class="icon-pencil-square-o"> 创作文章</strong>
		</div>
		<div class="padding border-bottom" align="center">
			<div class="layui-form-item layui-inline">
				<label class="layui-form-label">文章名：</label>
				<div class="layui-input-block">
					<input class="layui-input" id="title" name="title" autocomplete="off"/>
				</div>
			</div>
			<div class="layui-form-item layui-inline">
				<label class="layui-form-label">分类：</label>
				<div class="layui-input-block">
					<select id="groupsId" name="groupsId" class="layui-input" lay-verify="required" lay-search="">
						<option th:each="group:${groups}"  th:value="${group.getGroupsId()}" th:text="${group.getGname()}"></option>
					</select>
				</div>
			</div>
			<div class="layui-form-item layui-inline">
				<label class="layui-form-label">标签：</label>
				<div class="layui-input-block">
					<input id="tags" name="tags" class="layui-input" readonly="readonly"  placeholder="多个标签用;号间隔" autocomplete="off"/>
				</div>
			</div>
			<div class="layui-form-item layui-inline">
				<label class="layui-form-label">文章描述：</label>
				<div class="layui-input-block">
					<input id="description" name="description" class="layui-input" size="20"  placeholder="文章描述0-30字" autocomplete="off"/>
				</div>
			</div>
		</div>
		<div id="article-content">
			<textarea name="content" id="content" style=""></textarea>
		</div>
	</form>
	<input id="importFile" type="hidden" />
</div>
<div id="inputTags" style="display: none">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<div class="layui-card" id="okTags">
				<span class="layui-text">文章标签：</span>
			</div>
			<!--<div>
				<span class="layui-text layui-badge layui-badge-rim"><i class="layui-icon delTags" style="text-align: right;font-size: small">&#xe654;</i>添加标签</span>
			</div>-->
			<div class="layui-card" >
				<form class="layui-form">
					<h5 style="text-align: center">搜索标签</h5>
					<input id="selectTags" name="selectTags" class="layui-input" size="10"  placeholder="输入关键字" autocomplete="off"/>
				</form>
			</div>
			<div class="layui-card" id="seachTags">
				<span class="layui-text">搜索结果：</span>
			</div>
			<div class="layui-card" >
				<form class="layui-form">
					<h5 style="text-align: center">创建标签</h5>
					<input id="addTags" name="selectTags" class="layui-input" size="10"  placeholder="输入关键字" autocomplete="off"/>
				</form>
			</div>
		</div>
	</div>
</div>
</body>
<script th:src="@{/js/jquery.js}"></script>
<script th:src="@{/md/editormd.js}"></script>
<script th:src="@{/md/copyImg.js}"></script>
<script th:src="@{/layui/layui.js}"></script>

<script type="text/javascript">
	var num = 0;
	var testEditor;
	layui.use(['form', 'laydate'], function() {
		var form = layui.form,
				laydate = layui.laydate;

	});
	layui.use('upload', function(){
		var upload = layui.upload;
		var uploadInst = upload.render({
			elem: $("#importFile") //绑定元素
			,url: '/article/fileupload' //上传接口
			,accept: 'file' //允许上传的文件类型
			,acceptMime: 'file/txt,file/md'
			,exts: 'txt|md'
			,size: 10000 //最大允许上传的文件大小
			,drag: false
			,auto: true

			//上传前的回调
		/*	,before: function () {
				/!*this.data = {
                    'title': $('#title').val(),
                    'description': $('#description').val(),
                    'filegroupId':$('#filegroupId').val(),
                    'price':$('#price').val()
                };*!/
				console.log("this.data");  //查看是否成功获得数据
			}*/
			,done: function(res){
                //上传完毕回调
				if (res.code == 200){
					layui.use('layer',function(){
						layer=layui.layer;
						layer.msg('导入成功',{
							icon:1
						});
					});
					$("#content").text(res.data['content']);
					$("#title").val(res.data['title']);
					EditorData(res.data['content'])
				}else {
					layui.use('layer',function(){
						layer=layui.layer;
						layer.msg('导入失败',{
							icon:2
						});
					});
				}


            }
            ,error: function(){
                //请求异常回调
                alert("上传异常");
            }
		});
	});
	//window.onload = function(){ }
	$(function() {
		$("#tags").mouseover(function () {
			$(this).css("cursor","pointer")
		}).click(function () {
			queryTags();
			layer.open({
				type: 1,
				area: ["450px", "450px"],
				title: "我的账户",
				shade:false,
				content: $("#inputTags"),
				cancel: function(){
					//右上角关闭回调
					var txt = '';
					$('.inTags').each(function(i,n){
						$(n).children().remove();
						if (txt != ''){
							txt = txt + ';'
						}
						txt = txt + $(n).text()
					});
					$("#tags").val(txt);
				}
			})
		});
		$("#selectTags").on("input",function(e){
			queryTags($("#selectTags").val())
		});
		EditorData("# Editor.md\n" +
				"\n" +
				"![](https://pandao.github.io/editor.md/images/logos/editormd-logo-180x180.png)\n" +
				"\n" +
				"![](https://img.shields.io/github/stars/pandao/editor.md.svg) ![](https://img.shields.io/github/forks/pandao/editor.md.svg) ![](https://img.shields.io/github/tag/pandao/editor.md.svg) ![](https://img.shields.io/github/release/pandao/editor.md.svg) ![](https://img.shields.io/github/issues/pandao/editor.md.svg) ![](https://img.shields.io/bower/v/editor.md.svg)\n" +
				"\n" +
				"**目录 (Table of Contents)**\n" +
				"\n" +
				"[TOCM]\n" +
				"\n" +
				"[TOC]\n" +
				"\n" +
				"# Heading 1\n" +
				"## Heading 2               \n" +
				"### Heading 3\n" +
				"#### Heading 4\n" +
				"##### Heading 5\n" +
				"###### Heading 6\n" +
				"# Heading 1 link [Heading link](https://github.com/pandao/editor.md \"Heading link\")\n" +
				"## Heading 2 link [Heading link](https://github.com/pandao/editor.md \"Heading link\")\n" +
				"### Heading 3 link [Heading link](https://github.com/pandao/editor.md \"Heading link\")\n" +
				"#### Heading 4 link [Heading link](https://github.com/pandao/editor.md \"Heading link\") Heading link [Heading link](https://github.com/pandao/editor.md \"Heading link\")\n" +
				"##### Heading 5 link [Heading link](https://github.com/pandao/editor.md \"Heading link\")\n" +
				"###### Heading 6 link [Heading link](https://github.com/pandao/editor.md \"Heading link\")\n" +
				"\n" +
				"#### 标题（用底线的形式）Heading (underline)\n" +
				"\n" +
				"This is an H1\n" +
				"=============\n" +
				"\n" +
				"This is an H2\n" +
				"-------------\n" +
				"\n" +
				"### 字符效果和横线等\n" +
				"                \n" +
				"----\n" +
				"\n" +
				"~~删除线~~ <s>删除线（开启识别HTML标签时）</s>\n" +
				"*斜体字*      _斜体字_\n" +
				"**粗体**  __粗体__\n" +
				"***粗斜体*** ___粗斜体___\n" +
				"\n" +
				"上标：X<sub>2</sub>，下标：O<sup>2</sup>\n" +
				"\n" +
				"**缩写(同HTML的abbr标签)**\n" +
				"\n" +
				"> 即更长的单词或短语的缩写形式，前提是开启识别HTML标签时，已默认开启\n" +
				"\n" +
				"The <abbr title=\"Hyper Text Markup Language\">HTML</abbr> specification is maintained by the <abbr title=\"World Wide Web Consortium\">W3C</abbr>.\n" +
				"\n" +
				"### 引用 Blockquotes\n" +
				"\n" +
				"> 引用文本 Blockquotes\n" +
				"\n" +
				"引用的行内混合 Blockquotes\n" +
				"                    \n" +
				"> 引用：如果想要插入空白换行`即<br />标签`，在插入处先键入两个以上的空格然后回车即可，[普通链接](http://localhost/)。\n" +
				"\n" +
				"### 锚点与链接 Links\n" +
				"\n" +
				"[普通链接](http://localhost/)\n" +
				"\n" +
				"[普通链接带标题](http://localhost/ \"普通链接带标题\")\n" +
				"\n" +
				"直接链接：<https://github.com>\n" +
				"\n" +
				"[锚点链接][anchor-id] \n" +
				"\n" +
				"[anchor-id]: http://www.this-anchor-link.com/\n" +
				"\n" +
				"[mailto:test.test@gmail.com](mailto:test.test@gmail.com)\n" +
				"\n" +
				"GFM a-tail link @pandao  邮箱地址自动链接 test.test@gmail.com  www@vip.qq.com\n" +
				"\n" +
				"> @pandao\n" +
				"\n" +
				"### 多语言代码高亮 Codes\n" +
				"\n" +
				"#### 行内代码 Inline code\n" +
				"\n" +
				"执行命令：`npm install marked`\n" +
				"\n" +
				"#### 缩进风格\n" +
				"\n" +
				"即缩进四个空格，也做为实现类似 `<pre>` 预格式化文本 ( Preformatted Text ) 的功能。\n" +
				"\n" +
				"    <?php\n" +
				"        echo \"Hello world!\";\n" +
				"    ?>\n" +
				"    \n" +
				"预格式化文本：\n" +
				"\n" +
				"    | First Header  | Second Header |\n" +
				"    | ------------- | ------------- |\n" +
				"    | Content Cell  | Content Cell  |\n" +
				"    | Content Cell  | Content Cell  |\n" +
				"\n" +
				"#### JS代码　\n" +
				"\n" +
				"```javascript\n" +
				"function test() {\n" +
				"\tconsole.log(\"Hello world!\");\n" +
				"}\n" +
				" \n" +
				"(function(){\n" +
				"    var box = function() {\n" +
				"        return box.fn.init();\n" +
				"    };\n" +
				"\n" +
				"    box.prototype = box.fn = {\n" +
				"        init : function(){\n" +
				"            console.log('box.init()');\n" +
				"\n" +
				"\t\t\treturn this;\n" +
				"        },\n" +
				"\n" +
				"\t\tadd : function(str) {\n" +
				"\t\t\talert(\"add\", str);\n" +
				"\n" +
				"\t\t\treturn this;\n" +
				"\t\t},\n" +
				"\n" +
				"\t\tremove : function(str) {\n" +
				"\t\t\talert(\"remove\", str);\n" +
				"\n" +
				"\t\t\treturn this;\n" +
				"\t\t}\n" +
				"    };\n" +
				"    \n" +
				"    box.fn.init.prototype = box.fn;\n" +
				"    \n" +
				"    window.box =box;\n" +
				"})();\n" +
				"\n" +
				"var testBox = box();\n" +
				"testBox.add(\"jQuery\").remove(\"jQuery\");\n" +
				"```\n" +
				"\n" +
				"#### HTML 代码 HTML codes\n" +
				"\n" +
				"```html\n" +
				"<!DOCTYPE html>\n" +
				"<html>\n" +
				"    <head>\n" +
				"        <mate charest=\"utf-8\" />\n" +
				"        <meta name=\"keywords\" content=\"Editor.md, Markdown, Editor\" />\n" +
				"        <title>Hello world!</title>\n" +
				"        <style type=\"text/css\">\n" +
				"            body{font-size:14px;color:#444;font-family: \"Microsoft Yahei\", Tahoma, \"Hiragino Sans GB\", Arial;background:#fff;}\n" +
				"            ul{list-style: none;}\n" +
				"            img{border:none;vertical-align: middle;}\n" +
				"        </style>\n" +
				"    </head>\n" +
				"    <body>\n" +
				"        <h1 class=\"text-xxl\">Hello world!</h1>\n" +
				"        <p class=\"text-green\">Plain text</p>\n" +
				"    </body>\n" +
				"</html>\n" +
				"```\n" +
				"\n" +
				"### 图片 Images\n" +
				"\n" +
				"Image:\n" +
				"\n" +
				"![](https://pandao.github.io/editor.md/examples/images/4.jpg)\n" +
				"\n" +
				"> Follow your heart.\n" +
				"\n" +
				"![](https://pandao.github.io/editor.md/examples/images/8.jpg)\n" +
				"\n" +
				"> 图为：厦门白城沙滩\n" +
				"\n" +
				"图片加链接 (Image + Link)：\n" +
				"\n" +
				"[![](https://pandao.github.io/editor.md/examples/images/7.jpg)](https://pandao.github.io/editor.md/images/7.jpg \"李健首张专辑《似水流年》封面\")\n" +
				"\n" +
				"> 图为：李健首张专辑《似水流年》封面\n" +
				"                \n" +
				"----\n" +
				"\n" +
				"### 列表 Lists\n" +
				"\n" +
				"#### 无序列表（减号）Unordered Lists (-)\n" +
				"                \n" +
				"- 列表一\n" +
				"- 列表二\n" +
				"- 列表三\n" +
				"     \n" +
				"#### 无序列表（星号）Unordered Lists (*)\n" +
				"\n" +
				"* 列表一\n" +
				"* 列表二\n" +
				"* 列表三\n" +
				"\n" +
				"#### 无序列表（加号和嵌套）Unordered Lists (+)\n" +
				"                \n" +
				"+ 列表一\n" +
				"+ 列表二\n" +
				"    + 列表二-1\n" +
				"    + 列表二-2\n" +
				"    + 列表二-3\n" +
				"+ 列表三\n" +
				"    * 列表一\n" +
				"    * 列表二\n" +
				"    * 列表三\n" +
				"\n" +
				"#### 有序列表 Ordered Lists (-)\n" +
				"                \n" +
				"1. 第一行\n" +
				"2. 第二行\n" +
				"3. 第三行\n" +
				"\n" +
				"#### GFM task list\n" +
				"\n" +
				"- [x] GFM task list 1\n" +
				"- [x] GFM task list 2\n" +
				"- [ ] GFM task list 3\n" +
				"    - [ ] GFM task list 3-1\n" +
				"    - [ ] GFM task list 3-2\n" +
				"    - [ ] GFM task list 3-3\n" +
				"- [ ] GFM task list 4\n" +
				"    - [ ] GFM task list 4-1\n" +
				"    - [ ] GFM task list 4-2\n" +
				"                \n" +
				"----\n" +
				"                    \n" +
				"### 绘制表格 Tables\n" +
				"\n" +
				"| 项目        | 价格   |  数量  |\n" +
				"| --------   | -----:  | :----:  |\n" +
				"| 计算机      | $1600   |   5     |\n" +
				"| 手机        |   $12   |   12   |\n" +
				"| 管线        |    $1    |  234  |\n" +
				"                    \n" +
				"First Header  | Second Header\n" +
				"------------- | -------------\n" +
				"Content Cell  | Content Cell\n" +
				"Content Cell  | Content Cell \n" +
				"\n" +
				"| First Header  | Second Header |\n" +
				"| ------------- | ------------- |\n" +
				"| Content Cell  | Content Cell  |\n" +
				"| Content Cell  | Content Cell  |\n" +
				"\n" +
				"| Function name | Description                    |\n" +
				"| ------------- | ------------------------------ |\n" +
				"| `help()`      | Display the help window.       |\n" +
				"| `destroy()`   | **Destroy your computer!**     |\n" +
				"\n" +
				"| Left-Aligned  | Center Aligned  | Right Aligned |\n" +
				"| :------------ |:---------------:| -----:|\n" +
				"| col 3 is      | some wordy text | $1600 |\n" +
				"| col 2 is      | centered        |   $12 |\n" +
				"| zebra stripes | are neat        |    $1 |\n" +
				"\n" +
				"| Item      | Value |\n" +
				"| --------- | -----:|\n" +
				"| Computer  | $1600 |\n" +
				"| Phone     |   $12 |\n" +
				"| Pipe      |    $1 |\n" +
				"                \n" +
				"----\n" +
				"\n" +
				"#### 特殊符号 HTML Entities Codes\n" +
				"\n" +
				"&copy; &  &uml; &trade; &iexcl; &pound;\n" +
				"&amp; &lt; &gt; &yen; &euro; &reg; &plusmn; &para; &sect; &brvbar; &macr; &laquo; &middot; \n" +
				"\n" +
				"X&sup2; Y&sup3; &frac34; &frac14;  &times;  &divide;   &raquo;\n" +
				"\n" +
				"18&ordm;C  &quot;  &apos;\n" +
				"\n" +
				"[========]\n" +
				"\n" +
				"### Emoji表情 :smiley:\n" +
				"\n" +
				"> Blockquotes :star:\n" +
				"\n" +
				"#### GFM task lists & Emoji & fontAwesome icon emoji & editormd logo emoji :editormd-logo-5x:\n" +
				"\n" +
				"- [x] :smiley: @mentions, :smiley: #refs, [links](), **formatting**, and <del>tags</del> supported :editormd-logo:;\n" +
				"- [x] list syntax required (any unordered or ordered list supported) :editormd-logo-3x:;\n" +
				"- [x] [ ] :smiley: this is a complete item :smiley:;\n" +
				"- [ ] []this is an incomplete item [test link](#) :fa-star: @pandao; \n" +
				"- [ ] [ ]this is an incomplete item :fa-star: :fa-gear:;\n" +
				"    - [ ] :smiley: this is an incomplete item [test link](#) :fa-star: :fa-gear:;\n" +
				"    - [ ] :smiley: this is  :fa-star: :fa-gear: an incomplete item [test link](#);\n" +
				" \n" +
				"#### 反斜杠 Escape\n" +
				"\n" +
				"\\*literal asterisks\\*\n" +
				"\n" +
				"[========]\n" +
				"            \n" +
				"### 科学公式 TeX(KaTeX)\n" +
				"\n" +
				"$$E=mc^2$$\n" +
				"\n" +
				"行内的公式$$E=mc^2$$行内的公式，行内的$$E=mc^2$$公式。\n" +
				"\n" +
				"$$x > y$$\n" +
				"\n" +
				"$$\\(\\sqrt{3x-1}+(1+x)^2\\)$$\n" +
				"                    \n" +
				"$$\\sin(\\alpha)^{\\theta}=\\sum_{i=0}^{n}(x^i + \\cos(f))$$\n" +
				"\n" +
				"多行公式：\n" +
				"\n" +
				"```math\n" +
				"\\displaystyle\n" +
				"\\left( \\sum\\_{k=1}^n a\\_k b\\_k \\right)^2\n" +
				"\\leq\n" +
				"\\left( \\sum\\_{k=1}^n a\\_k^2 \\right)\n" +
				"\\left( \\sum\\_{k=1}^n b\\_k^2 \\right)\n" +
				"```\n" +
				"\n" +
				"```katex\n" +
				"\\displaystyle \n" +
				"    \\frac{1}{\n" +
				"        \\Bigl(\\sqrt{\\phi \\sqrt{5}}-\\phi\\Bigr) e^{\n" +
				"        \\frac25 \\pi}} = 1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {\n" +
				"        1+\\frac{e^{-6\\pi}}\n" +
				"        {1+\\frac{e^{-8\\pi}}\n" +
				"         {1+\\cdots} }\n" +
				"        } \n" +
				"    }\n" +
				"```\n" +
				"\n" +
				"```latex\n" +
				"f(x) = \\int_{-\\infty}^\\infty\n" +
				"    \\hat f(\\xi)\\,e^{2 \\pi i \\xi x}\n" +
				"    \\,d\\xi\n" +
				"```\n" +
				"\n" +
				"### 分页符 Page break\n" +
				"\n" +
				"> Print Test: Ctrl + P\n" +
				"\n" +
				"[========]\n" +
				"\n" +
				"### 绘制流程图 Flowchart\n" +
				"\n" +
				"```flow\n" +
				"st=>start: 用户登陆\n" +
				"op=>operation: 登陆操作\n" +
				"cond=>condition: 登陆成功 Yes or No?\n" +
				"e=>end: 进入后台\n" +
				"\n" +
				"st->op->cond\n" +
				"cond(yes)->e\n" +
				"cond(no)->op\n" +
				"```\n" +
				"\n" +
				"[========]\n" +
				"                    \n" +
				"### 绘制序列图 Sequence Diagram\n" +
				"                    \n" +
				"```seq\n" +
				"Andrew->China: Says Hello \n" +
				"Note right of China: China thinks\\nabout it \n" +
				"China-->Andrew: How are you? \n" +
				"Andrew->>China: I am good thanks!\n" +
				"```\n" +
				"\n" +
				"### End\n" +
				"            ")
	});
	function EditorData(data) {
		testEditor = editormd("article-content", {
			placeholder: "欢迎使用",
			value: data,
			width : "95%",
			height : "500px",
			syncScrolling : "single",
			path : "../md/lib/", //使用自己的路径
			saveHTMLToTextarea : true,    // 保存 HTML 到 Textarea
			emoji: true,
			/* theme: "dark",//工具栏主题
             previewTheme: "dark",//预览主题
             editorTheme: "pastel-on-dark",//编辑主题*/
			tex : true,                   // 开启科学公式TeX语言支持，默认关闭
			flowChart : true,             // 开启流程图支持，默认关闭
			sequenceDiagram : true,       // 开启时序/序列图支持，默认关闭,
			//图片上传
			imageUpload : true,
			imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
			imageUploadURL : "/article/file/upload", //图片上传路径
			onload : function() {
				console.log('onload', this);
				//加载完成后 配置生成目录
				testEditor.config("tocDropdown", true);
				initPasteDragImg(this); //必须
			},
			/*onload : function() {
				console.log('onload', this);
				//加载完成后 配置生成目录
				testEditor.config("tocDropdown", true);

			},*/
			/*onload : function() {
				console.log('onload', this);
				//加载完成后 配置生成目录
				testEditor.config({
					tocDropdown   : true,
					tocTitle      : "目录 Table of Contents",
				});

			},*/
			/*指定需要显示的功能按钮*/
			toolbarIcons : function() {
				return ["undo","redo","|",
					"bold","del","italic","quote","ucwords","uppercase","lowercase","|",
					"h1","h2","h3","h4","h5","h6","|",
					"list-ul","list-ol","hr","|",
					"link","reference-link","image","code","preformatted-text",
					"code-block","table","datetime","emoji","html-entities","pagebreak","|",
					"goto-line","watch","preview","fullscreen","clear","search","|",
					"help","info","importFile","releaseIcon", "index"]
			},

			/*自定义功能按钮，下面我自定义了2个，一个是发布，一个是返回首页*/
			toolbarIconTexts : {
				releaseIcon : "<span bgcolor=\"gray\">发布</span>",
				index : "<span bgcolor=\"red\">返回首页</span>",
				importFile : "<span bgcolor=\"red\">导入文件</span>"
			},

			/*给自定义按钮指定回调函数*/
			toolbarHandlers:{
				importFile: function(){
					$("#importFile").click();
				},
				releaseIcon : function(cm, icon, cursor, selection) {
					//表单提交
					console.log($("#content").val());
					var content = $("#content").val();
					if (content == ""){
						layui.use('layer',function(){
							layer=layui.layer;
							layer.msg('内容不能为空',{
								icon:2
							});
						})
						return
					}
					var title = $("#title").val();
					if (title == ""){
						layui.use('layer',function(){
							layer=layui.layer;
							layer.msg('标题不能为空',{
								icon:2
							});
						})
						return
					}
					if ($("#groupsId").val() == ""){
						layui.use('layer',function(){
							layer=layui.layer;
							layer.msg('分组不能为空',{
								icon:2
							});
						})
						return
					}
					if ($("#tags").val() == ""){
						layui.use('layer',function(){
							layer=layui.layer;
							layer.msg('标签不能为空',{
								icon:2
							});
						})
						return
					}
					var article = {};
					article["title"] = title;
					article["content"]=content;
					article["groupsId"]=$("#groupsId").val();
					article["tags"]=$("#tags").val();
					article["description"]=$("#description").val();
					addArticle(article)
					// mdEditorForm.method = "post";
					// mdEditorForm.action = "/article/addArticle?contentCheck="+content;//提交至服务器的路径
					// mdEditorForm.submit();
				},
				index : function(){
					window.location.href = '/article/add_article';//刷新当前页面
				},
			}
		});
	}
	function addArticle(data) {
		$.ajax({
			type:'post',
			url:'/article/addArticle',
			data:data,
			async: false,
			success:function (data) {
				if (data.code==200){
					layui.use('layer',function(){
						layer=layui.layer;
						layer.msg(data.msg,{
							icon:1
						});
					});
					window.location.href = "/article/data_article"
				}else {
					layui.use('layer',function(){
						layer=layui.layer;
						layer.msg("发布失败",{
							icon:2
						});
					})
				}

			}
		});
	}
	function queryTags(name) {

		var url = '/tags/queryTags?search='+name;
		if (name == null || name == ''){
			num = 0;
			url = '/tags/queryTags';
			$("#okTags").empty().append('<span class="layui-text">文章标签：</span>')
		}
		$.ajax({
			type:'post',
			url: url,
			async: false,
			success:function (data) {
				if (data.code==200){
					console.log(data.data);
					seachTags = $("#seachTags");
					var txt = '<span class="layui-text">搜索结果：</span>';
					$.each(data.data,function (index,domEle){
						txt = txt + '<span class="layui-text layui-badge layui-bg-blue seachTags" style="line-height: 20px">'+domEle.name+'</span>&nbsp;'
					});
					seachTags.empty();
					seachTags.append(txt);
					$('.seachTags').each(function(i,n){
						$(n).on('click',function(){
							txt = $('<span class="layui-text layui-badge layui-bg-blue inTags" style="margin-right: 10px">' + $(n).text() + '</span>');
							var deltxt = $('<i class="layui-icon delTags" style="text-align: right;font-size: small">&#x1006;</i>');
							deltxt.click(function () {
								num = num - 1;
								$(this).parent().remove();
							});
							txt.append(deltxt);
							if (num > 2){
								alert("最多添加3个标签")
							}else {
								num = Number(num) + Number(1);
								$("#okTags").append(txt)
							}
						})
					});
				}else {
					layui.use('layer',function(){
						layer=layui.layer;
						layer.msg(data.msg,{
							icon:2
						});
					})
				}
			}
		});

	}
</script>

</html>